package no.progark.golf.controller;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import no.progark.golf.Golf;
import no.progark.golf.activities.GameSettingsActivity;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageButton;

public class OptionsController implements PropertyChangeListener {

	
	private static Button saveOptionsButton;
	private static CheckBox musicOptionCheckBox;
	private static CheckBox soundEffectsOptionCheckBox;
	private static CheckBox ffOptionsCheckBox;
	private static Context context;
	private static Activity activity;
	private static boolean musicTest;
	
	
	public static void setContextAndActivity(Context c){
//		Golf.getInstance().addPropertyChangeListener(this);
		OptionsController.context = c;
		OptionsController.activity = (Activity) c;
		
	}
	
	
	
	public static void setSaveOptionButton(Button b){
		OptionsController.saveOptionsButton = b;
		saveOptionsButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
//				Golf.getInstance().setMusicEnabled(musicOptionCheckBox.isChecked());
				Golf.getInstance().setSoundEffectsEnabled(soundEffectsOptionCheckBox.isChecked());
				Golf.getInstance().setFriendlyFire(ffOptionsCheckBox.isChecked());
				
				activity.finish();
				
			}
			
		
		});
	}
	
	public static void setMusicOptionCheckBox(CheckBox b){
		OptionsController.musicOptionCheckBox = b;
		if(Golf.getInstance().isMusicEnabled()){
			musicOptionCheckBox.setChecked(true);
			
		}
		musicOptionCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				// TODO Auto-generated method stub
				if ( isChecked )
		        {
					Golf.getInstance().setMusicEnabled(true);
		        }
				else{
					Golf.getInstance().setMusicEnabled(false);
				}
				MainMenuController.setMusic();
			}
		});
//		if(musicTest){
//			musicOptionCheckBox.setChecked(true);
//		}
	}
	public static void setSoundEffectOptionCheckBox(CheckBox b){
		OptionsController.soundEffectsOptionCheckBox = b;
		if(Golf.getInstance().isSoundEffectsEnabled()){
			soundEffectsOptionCheckBox.setChecked(false);
			
		}
	}
	public static void setFfOptionCheckBox(CheckBox b){
		OptionsController.ffOptionsCheckBox = b;
		if(Golf.getInstance().isFriendlyFire()){
			ffOptionsCheckBox.setChecked(false);
			
		}
	}



	@Override
	public void propertyChange(PropertyChangeEvent event) {
		// TODO Auto-generated method stub
//		if(event.getPropertyName().equals("music")){
//			musicTest=Golf.getInstance().isMusicEnabled();
//		}
	}
}
